321 - The New Villa (Grafos, BFS, bitwise)
[andmenj-acm.git] / 846 - Steps / p846.cpp
blob0dc59e81a9b6d1d7f73b9bdeb0ec486f2197740f
1 #include <iostream>
2 using namespace std;
4 long f(long x){
5 if (x == 0) return 0;
6 long raiz = 1;
7 while (raiz*raiz <= x) ++raiz;
8 --raiz;
9 long suma = raiz * raiz;
10 long terminos = 2*raiz-1;
11 long diferencia = x - suma;
12 long i = raiz;
13 while (diferencia > 0){
14 if (diferencia - i >=0){
15 diferencia -= i;
16 ++terminos;
17 }else --i;
19 return terminos;
23 int main(){
24 int n;
25 cin >> n;
26 while (n-- > 0){
27 long x, y;
28 cin >> x >> y;
29 cout << f(y-x) << endl;
31 return 0;